#include "RingQueue.hpp"
#include <unistd.h>

struct threaddata
{
    RingQueue<int>* rq;
    std::string name;
};

void* consumer(void* args)
{
    threaddata* td = static_cast<threaddata*>(args);
    while(true)
    {
        sleep(10);
        int t;
        td->rq->Pop(&t);
        std::cout << "消费了一个任务:" << t << std::endl;
    }
}

int data = 1;
void* productor(void* args)
{
    threaddata* td = static_cast<threaddata*>(args);
    while(true)
    {
        td->rq->Equeue(data);
        std::cout << td->name << "生产了一个任务:" << data << std::endl;
        data++;
    }
}

int main()
{
    RingQueue<int>* rq = new RingQueue<int>();
    pthread_t c,p;

    threaddata* td1 = new threaddata;
    td1->name = "thread-1";
    td1->rq = rq;
    pthread_create(&c, nullptr, consumer, td1);

    threaddata* td2 = new threaddata;
    td2->name = "thread-2";
    td2->rq = rq;
    pthread_create(&p, nullptr, productor, td2);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);

    return 0;
}